import { fileURLToPath, URL } from 'node:url'
import vueSetupExtend from 'vite-plugin-vue-setup-extend'
import { defineConfig, loadEnv } from 'vite'
import Components from 'unplugin-vue-components/vite'
import { AntDesignVueResolver } from 'unplugin-vue-components/resolvers'
import vue from '@vitejs/plugin-vue'
//自动导入
import AutoImport from 'unplugin-auto-import/vite'
// https://vitejs.dev/config/
export default ({ mode }) => {
  const config = loadEnv(mode, './')
  console.log(config)
  return defineConfig({
    server: {
      port: 8888,
      //
      proxy: {
        '/api': {
          target: config.VITE_APP_URL,
          changeOrigin: true //允许跨域
        }
      }
    },
    plugins: [
      AutoImport({
        imports: ['vue', 'vue-router'],
        //检查代码
        //自动生成文件
        eslintrc: {
          enabled: true
        }
      }),
      vueSetupExtend(),
      vue(),
      Components({
        resolvers: [
          AntDesignVueResolver({
            importStyle: false // css in js
          })
        ]
      })
    ],
    resolve: {
      alias: {
        '@': fileURLToPath(new URL('./src', import.meta.url))
      }
    }
  })
}
